﻿package server;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ResStaff {
	private Data data;
	/*private int staffNumber;
	private String name;
	private double salary;
	private double isBusy;*/
	

	/*public int getStaffNumber() {
		return staffNumber;
	}

	public void setStaffNumber(int staffNumber) {
		this.staffNumber = staffNumber;
	}*/
	
	public ResStaff(){
		data=new Data();
	}

	public double getSalary(int staffNumber) {
		String sql;
		ResultSet rs=null;
		double salary=0;
		
		sql="select * from resstaff where id=" + staffNumber;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				salary=rs.getDouble("salary");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
			
		return salary;
	}

	public boolean setSalary(int staffNumber,double salary) {
		String sql;
		int re=0;
		
		sql="update resstaff set salary = "+salary+" where id="+staffNumber;
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
	}

	public String getName(int staffNumber) {
		String sql;
		ResultSet rs=null;
		String name="";
		
		sql="select * from resstaff where id=" + staffNumber;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				name=rs.getString("name");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
			
		return name;
	}

	public boolean setName(int staffNumber,String name) {
		String sql;
		int re=0;
		
		sql="update resstaff set name = '"+name+"' where id="+staffNumber;
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
	}

	public int getSize() {
		String sql;
		ResultSet rs=null;
		int sum=0;
		
		sql="select count(*) as sum from resstaff";
		rs=data.getResultSet(sql);
		try {
			if(rs.next()){
				sum=rs.getInt("sum");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
			
		return sum;
	}
	
	
}
